package uns.fit.gis.mapdrawer;

import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.Graphics;

import uns.fit.gis.contextmenu.BestRouteContextMenu;
import uns.fit.gis.contextmenu.ContextMenu;
import uns.fit.gis.contextmenu.GPSContextMenu;
import uns.fit.gis.mapobj.Point;

public class TestCanvas2 extends Canvas {
	private int angle = 10;
	private ContextMenu contextMenu;
	
	public TestCanvas2() {
		
	}
	
	protected void paint(Graphics g) {
		// TODO Auto-generated method stub
		/*
		long s = System.currentTimeMillis();
		g.setColor(244, 164, 96);
		DirectionArrowDrawer.draw(g, 20, 30, 200, 300, 5);
		System.out.println(System.currentTimeMillis() - s);
		*/
	}

	private void drawQuad(Graphics g, Point p0, Point p1, Point p2, Point p3) {
		g.drawLine(p0.getX(), p0.getY(), p1.getX(), p1.getY());
		g.drawLine(p1.getX(), p1.getY(), p2.getX(), p2.getY());
		g.drawLine(p2.getX(), p2.getY(), p3.getX(), p3.getY());
		g.drawLine(p3.getX(), p3.getY(), p0.getX(), p0.getY());
	}
	
	protected void keyPressed(int keyCode) {
		switch(keyCode) {
		case Canvas.KEY_NUM7:
			angle -= 10;
			break;
		case Canvas.KEY_NUM9:
			angle += 10;
			break;
		case Canvas.KEY_NUM1:
			if(contextMenu == null) {
				contextMenu = new GPSContextMenu();
				contextMenu.attach(this);
			}
			else {
				contextMenu.detach(this);
				contextMenu = new GPSContextMenu();
				contextMenu.attach(this);
			}
			break;
		case Canvas.KEY_NUM3:
			if(contextMenu == null) {
				contextMenu = new BestRouteContextMenu();
				contextMenu.attach(this);
			}
			else {
				contextMenu.detach(this);
				contextMenu = new BestRouteContextMenu();
				contextMenu.attach(this);
			}
			break;
		default:
			break;
		}
		repaint();
	}
	
	protected void keyRepeated(int keyCode) {
		keyPressed(keyCode);
	}
}
